/*
 * @Author: WangLi
 * @Date: 2021-08-04 23:15:40
 * @LastEditors: WangLi
 * @LastEditTime: 2022-09-07 16:08:49
 * @Description:
 */
const IMAGE_REGEXP = /\.(jpeg|jpg|gif|png|svg|webp|jfif|bmp|dpg)/i;
const VIDEO_REGEXP = /\.(mp4|mpg|mpeg|dat|asf|avi|rm|rmvb|mov|wmv|flv|mkv)/i;
export const PHONE_REGEXP =
  /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
export const IDCARD_REGEXP =
  /^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
export const CARDNUMBER_REGEXP = /^\d+$|^\d+[.]?\d+$/;
const NUMBER_REGEXP = /^\d+$/;

export function isFunction(val) {
  return typeof val === "function";
}

export function isPlainObject(val) {
  return val !== null && typeof val === "object" && !Array.isArray(val);
}

export function isPromise(val) {
  return isPlainObject(val) && isFunction(val.then) && isFunction(val.catch);
}

export function isDef(value) {
  return value !== undefined && value !== null;
}

export function isObj(x) {
  const type = typeof x;
  return x !== null && (type === "object" || type === "function");
}

export function isNumber(value) {
  return /^\d+(\.\d+)?$/.test(value);
}

export function isBoolean(value) {
  return typeof value === "boolean";
}

export function isImageUrl(url) {
  return IMAGE_REGEXP.test(url);
}

export function isVideoUrl(url) {
  return VIDEO_REGEXP.test(url);
}

export function isPhone(params) {
  return PHONE_REGEXP.test(params);
}

export function idCard(params) {
  return IDCARD_REGEXP.test(params);
}

export function cardNumber(params) {
  return CARDNUMBER_REGEXP.test(params);
}
